package com.yxy.f_music_server.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yxy.f_music_server.common.PageResult;
import com.yxy.f_music_server.constant.StatusConstant;
import com.yxy.f_music_server.domain.dto.FeedbackDTO;
import com.yxy.f_music_server.domain.dto.FeedbackPageQueryDTO;
import com.yxy.f_music_server.domain.po.Feedback;
import com.yxy.f_music_server.domain.vo.FeedbackPageQueryVO;
import com.yxy.f_music_server.exception.FileUploadException;
import com.yxy.f_music_server.mapper.FeedbackMapper;
import com.yxy.f_music_server.service.FeedbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 添加反馈
     * @param feedbackDTO
     */
    @Override
    public void add(FeedbackDTO feedbackDTO) {
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(feedbackDTO, feedback);
        feedback.setCreateTime(LocalDateTime.now());
        feedback.setStatus(StatusConstant.REVIEW);
        feedbackMapper.add(feedback);
    }

    /**
     * 获取反馈列表
     * @param feedbackPageQueryDTO
     * @return
     */
    @Override
    public PageResult getFeedbackList(FeedbackPageQueryDTO feedbackPageQueryDTO) {
        PageHelper.startPage(feedbackPageQueryDTO.getPage(), feedbackPageQueryDTO.getPageSize());
        Page<FeedbackPageQueryVO> page = feedbackMapper.getFeedbackList(feedbackPageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }
}
